<?php 

$categoryId=$_POST['categoryId'];
$currentPage=$_POST['currentPage'];
$pageSize=$_POST['pageSize'];

$offset=($currentPage-1)* $pageSize;

include_once '../common/sql.php';

$conn=connect();
$sql="select p.id,p.title,p.feature,p.created,p.content,p.views,p.likes,u.nickname,c.`name`,
    (select count(*) from comments where comments.post_id=p.id) commentsCount
    from posts p
    left join users u on u.id= p.user_id 
    left join categories c on c.id=p.category_id
    where p.category_id=$categoryId
    limit $offset,$pageSize";
 
    $arr=query($conn,$sql);

    $pageSql="select count(*)  count from posts where category_id=$categoryId";

    $newArr=query($conn,$pageSql);
    $count=$newArr[0]['count'];
 
    $res=array("code"=>0,"msg"=>'请求失败');
   
    if($arr){
        $res['code']=1;
        $res['msg']='请求成功';
        $res['data']=$arr;
        $res['count']=$count;
    }
    echo json_encode($res);
  ?>